<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use yii\helpers\Url;
use common\models\Activity\Activity;
use common\models\customInfo\CustomInfo;
use yii\helpers\ArrayHelper;
use dosamigos\datetimepicker\DateTimePicker;//时间
/* @var $this yii\web\View */
/* @var $searchModel common\models\Activity\ActivitySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', '活动管理');
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginBlock('siderbar'); ?>
<?= $this->render('//layouts/act-menu') ?>
<?php $this->endBlock(); ?>
<div class="activity-index">
    <p>
        <?= Html::a(Yii::t('app', '新增'), ['create'], ['class' => 'btn btn-success']) ?>
        <button class="btn btn-success" id="start" type="button">发布</button>
        <button class="btn btn-danger" id="alldel" type="button">删除</button>
    </p>
 <?= GridView::widget([
        'id' => "myform",
        'pjax'=>false,
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'containerOptions'=>['style'=>'overflow: auto'], // only set when $responsive = false
        'headerRowOptions'=>['class'=>'kartik-sheet-style'],
        'filterRowOptions'=>['class'=>'filters'],
        'panel'=>[
            'heading'=>'<h3 class="panel-title"><i class="glyphicon glyphicon-globe"></i> 数据列表</h3>',
            'type'=>'default',
            'footer'=>false
        ],
        'toolbar' => [],
        'pager'=>[
            'options'=>['class'=>'hidden']//关闭自带分页
        ],
        'persistResize'=>false,

        'columns' => [
            [
                'class'=>'kartik\grid\CheckboxColumn',
                'headerOptions'=>['class'=>'my-table'],
            ],
            'ac_id',
            'ac_name',
            [
                'attribute' => 'la_id',
                'value' => function($model) {
                   return Activity::getLabel($model->la_id);
                },   
            ],
            //'ac_desciption',
            [
                'attribute' => 'start_time',
                'format' => ['date', 'Y-M-d H:i'],
            ],
            [
                'attribute' => 'end_time',
                'format' => ['date', 'Y-M-d H:i'],
            ],
            'ac_man',
            [
                'attribute' => 'g_id',
                'value' => function($model) {
                   return Activity::getGuest($model->g_id);
                },   
            ],
			[
                'attribute' => 'cu_id',
                'value' => function($model) {
                   return Activity::getCum($model->cu_id);
                },   
            ],
            'ac_phone',
            [
                'attribute' => 'ac_number',
                'value' => function($model) {
                   return CustomInfo::find()->where(['ac_id' => $model->ac_id])->count();
                },   
            ],
			'ac_cost',
            [
                'attribute' => 'ac_status',
                'format' => 'html',
                'value' => function ($model) {
                    if ($model->ac_status === $model::ACSTATUS_ACTIVE) {
                        $class = 'label-success';
                    } elseif ($model->ac_status === $model::ACSTATUS_DELETED) {
                        $class = 'label-warning';
                    } else {
                        $class = 'label-danger';
                    }
                    return '<span class="label ' . $class . '">' . $model->statusLabel . '</span>';
                },
                'filterType'=>GridView::FILTER_SELECT2,
                'filter'=>Activity::getArrayStatus(),
                'filterWidgetOptions'=>[
                    'pluginOptions'=>['allowClear'=>true],
                ],
                'filterInputOptions'=>['placeholder'=>'全部'],
                'format'=>'raw'
            ],
            [
                'attribute' => 'ac_display',
                'format' => 'html',
                'value' => function ($model) {
                    if ($model->ac_display == $model::DIS_DELETED) {
                        $class = 'label-success';
                    } elseif ($model->ac_display == $model::DIS_SUCCESS) {
                        $class = 'label-warning';
                    } else {
                        $class = 'label-danger';
                    }

                    return '<span class="label ' . $class . '">' . $model->gradeLabel . '</span>';
                },
                'filterType'=>GridView::FILTER_SELECT2,
                'filter'=>Activity::getArrayGrade(),
                'filterWidgetOptions'=>[
                    'pluginOptions'=>['allowClear'=>true],
                ],
                'filterInputOptions'=>['placeholder'=>'全部'],
                'format'=>'raw'

            ],
            //'ac_arrange',
            //'ac_field',
            //'ac_sponsor',
            [
                'class' => 'yii\grid\ActionColumn',
                'header' => '操作',
                'template' => '{view}{update}{delete}{baominginfo}',
                'headerOptions' => ['width' => '200'],
                'buttons' => [
                    'view' => function ($url, $model, $key) {
                        return  Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-eye-open" ><span class="classformat">查看</span></span>', $url, ['title' => '查看'] ) ;
                    },
                    'baominginfo' => function ($url, $model, $key) {
                        return  Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-eye-open" ><span class="classformat">报名信息</span></span>', ['/custom-info/index', 'id' => $model->ac_id]);
                    },
                    'update' => function ($url, $model, $key) {
                        return Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-pencil"><span class="classformat">修改</span></span>', $url, ['title' => '修改'] ) ;
                    },
                    'delete' => function ($url, $model, $key) {
                        return Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-trash" ><span class="classformat">删除</span></span>', $url, [
                            'title' => '删除',
                            'data'=>[
                                'confirm'=>'你确定要删除'.$model->ac_name.'吗？',
                                'method'=>'post'
                            ]
                        ] ) ;
                    },
                ],
            ],
        ],
    ]); ?>
    <?= \backend\components\GoLinkPager::widget([
        'pagination' => $dataProvider->pagination,
        'go' => true,
    ]); ?>

</div>
<?php $this->beginBlock('footer_scripts'); ?>
    <script>
        $(document).ready(function(){
            bindqiyong("<?php echo Url::to(['activity/start']);?>");
            binddel("<?php echo Url::to(['activity/alldelete']);?>");
        });
    </script>
<?php $this->endBlock(); ?>